package com.erp.gather.controller;

import com.erp.gather.service.IErpProductArea64Service;
import com.erp.gather.service.IErpProductAreaService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.gather.api.domain.bo.ErpProductArea64Bo;
import com.ruoyi.gather.api.domain.vo.ErpProductArea64Vo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 商品区域国家
 *
 * @author erp
 * @date 2023-03-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/productArea64")
public class ErpProductArea64Controller extends BaseController {

    private final IErpProductArea64Service iErpProductAreaService;

    @GetMapping("/queryArea64ListInfo")
	public R<Object> queryArea64ListInfo() {
		List<ErpProductArea64Vo> list = iErpProductAreaService.queryList(new ErpProductArea64Bo());
		List<Map<String, Object>> collect = list.stream().map(vo -> {
			Map<String, Object> map = new HashMap<>();
			map.put("lable", vo.getAreaNo());
			map.put("value", vo.getAreaName());
			return map;
		}).collect(Collectors.toList());
		return R.ok(collect);
	}

    @GetMapping("/queryArea64List")
	public R<Object> queryArea64List() {
		List<ErpProductArea64Vo> list = iErpProductAreaService.queryList(new ErpProductArea64Bo());
		return R.ok(list);
	}

    /**
     * 查询商品区域国家列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpProductArea64Vo> list(ErpProductArea64Bo bo, PageQuery pageQuery) {
        return iErpProductAreaService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取商品区域国家详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpProductArea64Vo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpProductAreaService.queryById(id));
    }

    /**
     * 新增商品区域国家
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpProductArea64Bo bo) {
        return toAjax(iErpProductAreaService.insertByBo(bo));
    }

    /**
     * 修改商品区域国家
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpProductArea64Bo bo) {
        return toAjax(iErpProductAreaService.updateByBo(bo));
    }

    /**
     * 删除商品区域国家
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpProductAreaService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
